<Project>
  <!--
    Common files don't take part in the root tests\src\Directory.Build.targets
    This file prevents them from including it as it gets included in its place
    If they ever need to take part, we can conditionally include them as documented
    here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
  -->
  <Import Project="$(MSBuildThisFileDirectory)/disableversioncheck.targets"
          Condition="'$(DisableVersionCheckImported)' != 'true'" />

  <Import Project="$(RepoRoot)eng/liveBuilds.targets" />

  <PropertyGroup>
    <GCStressDependsOnCoreDisTools>false</GCStressDependsOnCoreDisTools>
    <GCStressDependsOnCoreDisTools Condition="'$(TargetOS)' == 'windows' And ('$(TargetArchitecture)' == 'x64' Or '$(TargetArchitecture)' == 'x86')">true</GCStressDependsOnCoreDisTools>
    <GCStressDependsOnCoreDisTools Condition="'$(TargetOS)' == 'linux' And '$(TargetArchitecture)' == 'x64'">true</GCStressDependsOnCoreDisTools>
    <CopyCoreDisToolsToCoreRoot>false</CopyCoreDisToolsToCoreRoot>
    <CopyCoreDisToolsToCoreRoot Condition="$(GCStressDependsOnCoreDisTools) And '$(DotNetBuildSourceOnly)' != 'true'">true</CopyCoreDisToolsToCoreRoot>
    <!-- Non-desktop OS's use a custom dotnet host, instead of corerun -->
    <IsDesktopOS Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsAndroid)' != 'true' and '$(TargetstvOS)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetsMacCatalyst)' != 'true'">true</IsDesktopOS>
  </PropertyGroup>

  <Import Project="$(RepositoryEngineeringDir)coredistools.targets" Condition="$(CopyCoreDisToolsToCoreRoot)" />

  <ItemGroup>
    <KnownFrameworkReference Remove="Microsoft.AspNetCore.App" />
    <KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
  </ItemGroup>

  <ItemDefinitionGroup>
    <RunTimeArtifactsIncludeFolders>
      <IncludeSubFolders>false</IncludeSubFolders>
    </RunTimeArtifactsIncludeFolders>
  </ItemDefinitionGroup>

  <Target Name="CopyDependencyToCoreRoot"
          DependsOnTargets="ResolveAssemblyReferences;ResolveRuntimeFilesFromLocalBuild">

    <ItemGroup>
      <RunTimeDependencyCopyLocal Include="@(RuntimeCopyLocalItems)" />
      <RunTimeDependencyCopyLocal Include="@(NativeCopyLocalItems)" />
      <RunTimeDependencyCopyLocal Include="$(TargetingPackPath)/*" />
      <RunTimeDependencyCopyLocal Include="$(TargetingPackPath)/xunit.*" TargetDir="xunit/" />
    </ItemGroup>

    <ItemGroup>
      <RunTimeArtifactsExcludeFiles Include="PDB/createdump.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/linuxonjit.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/mcs.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/mscordaccore.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/mscordbi.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/mscorrc.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/clrjit_*.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/superpmi.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/superpmi-shim-collector.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/superpmi-shim-counter.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/superpmi-shim-simple.pdb" />
    </ItemGroup>

    <!-- A sanitized DAC and DBI can't be loaded into a debugger process, so copy the non-sanitized versions instead -->
    <ItemGroup Condition="'$(EnableNativeSanitizers)' != ''">
      <SanitizedDiagnosticTools Include="$(CoreCLRArtifactsPath)/*mscordaccore*" />
      <SanitizedDiagnosticTools Include="$(LibPrefix)mscordbi$(LibSuffix)" />
      <SanitizedDiagnosticTools Include="$(LibPrefix)dbgshim$(LibSuffix)" />
      <RunTimeArtifactsExcludeFiles Include="@(SanitizedDiagnosticTools->'%(FileName)%(Extension)')" />
      <RunTimeArtifactsIncludeFolders Include="unsanitized/" TargetDir="/" />
    </ItemGroup>

    <ItemGroup Condition="'$(MinimalCoreRoot)' == 'true'">
      <RunTimeArtifactsExcludeFiles Include="PDB/ilasm.pdb" />
      <RunTimeArtifactsExcludeFiles Include="PDB/ildasm.pdb" />
    </ItemGroup>

    <ItemGroup>
      <RunTimeArtifactsIncludeFolders Include="/" TargetDir="/" />

      <!-- Experiment -->
      <RunTimeArtifactsIncludeFolders Include="R2RDump/" TargetDir="R2RDump/" />

      <!-- Used by the Crossgen comparison job -->
      <RunTimeArtifactsIncludeFolders Include="IL/" TargetDir="IL/" />

      <!-- Used for Crossgen2 R2R tests -->
      <RunTimeArtifactsIncludeFolders Include="crossgen2/" TargetDir="crossgen2/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used for NativeAOT tests -->
      <RunTimeArtifactsIncludeFolders Include="ilc-published/" TargetDir="ilc-published/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used for NativeAOT tests -->
      <RunTimeArtifactsIncludeFolders Include="aotsdk/" TargetDir="aotsdk/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used for NativeAOT tests -->
      <RunTimeArtifactsIncludeFolders Include="build/" TargetDir="build/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used for capturing symbolic stack traces using Watson -->
      <RunTimeArtifactsIncludeFolders Include="PDB/" TargetDir="PDB/" />

      <!-- Used by the coreroot_determinism test -->
      <RunTimeArtifactsIncludeFolders Include="R2RTest/" TargetDir="R2RTest/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used by tests checking PDB validity -->
      <RunTimeArtifactsIncludeFolders Include="PdbChecker/" TargetDir="PdbChecker/" />

      <!-- Used by disasm output verification tests -->
      <RunTimeArtifactsIncludeFolders Include="SuperFileCheck/" TargetDir="SuperFileCheck/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- Used to determine if a file is a managed assembly or a managed assembly built with DEBUG -->
      <RunTimeArtifactsIncludeFolders Include="AssemblyChecker/" TargetDir="AssemblyChecker/">
        <IncludeSubFolders>True</IncludeSubFolders>
      </RunTimeArtifactsIncludeFolders>

      <!-- XUnit runner harness assemblies that we don't want to mix in with the framework in Core_Root -->
      <RunTimeArtifactsIncludeFolders Include="xunit/" TargetDir="xunit/" />
    </ItemGroup>

    <ItemGroup>
      <!-- Add binary dependencies to copy-local items -->
      <RunTimeDependencyCopyLocal
          Condition="'%(RuntimeArtifactsIncludeFolders.IncludeSubFolders)' != 'True'"
          Include="$(CoreCLRArtifactsPath)%(RunTimeArtifactsIncludeFolders.Identity)*"
          Exclude="@(RunTimeArtifactsExcludeFiles -> '$(CoreCLRArtifactsPath)%(Identity)')"
          TargetDir="%(RunTimeArtifactsIncludeFolders.TargetDir)" />

      <RunTimeDependencyCopyLocal
          Condition="'%(RuntimeArtifactsIncludeFolders.IncludeSubFolders)' == 'True'"
          Include="$(CoreCLRArtifactsPath)%(RunTimeArtifactsIncludeFolders.Identity)**/*"
          Exclude="@(RunTimeArtifactsExcludeFiles -> '$(CoreCLRArtifactsPath)%(Identity)')"
          TargetDir="%(RunTimeArtifactsIncludeFolders.TargetDir)" />
    </ItemGroup>

    <PropertyGroup>
      <Crossgen2Dir />
      <Crossgen2Dir Condition="('$(TargetArchitecture)' != 'x64' and '$(BuildArchitecture)' == 'x64') or '$(EnableNativeSanitizers)' != ''">$(CoreCLRArtifactsPath)x64/crossgen2</Crossgen2Dir>
    </PropertyGroup>

    <ItemGroup Condition="'$(Crossgen2Dir)' != ''">
      <RunTimeDependencyCopyLocal
          Include="
            $(Crossgen2Dir)/$(LibPrefix)clrjit_*$(LibSuffix);
            $(Crossgen2Dir)/$(LibPrefix)jitinterface_*$(LibSuffix);
            $(Crossgen2Dir)/$(LibPrefix)Microsoft.DiaSymReader.Native.*$(LibSuffix)"
          TargetDir="crossgen2/" />
    </ItemGroup>

    <ItemGroup Condition="'$(TargetArchitecture)' == 'wasm'">
        <RunTimeDependencyCopyLocal
          Include="@(RuntimeFiles)"
          TargetDir="runtimepack/native/"/>

        <!-- This throws everything in 'native', include many non-native assemblies.
             This is done because LibrariesRuntimeFiles includes some .js files that
             WasmAppBuilder expects in native/-->
        <RunTimeDependencyCopyLocal
          Include="@(LibrariesRuntimeFiles)"
          TargetDir="runtimepack/native/%(LibrariesRuntimeFiles.NativeSubDirectory)/"
          Condition="'%(LibrariesRuntimeFiles.NativeSubDirectory)' != ''" />

        <RunTimeDependencyCopyLocal
          Include="@(LibrariesRuntimeFiles)"
          TargetDir="runtimepack/native/"
          Condition="'%(LibrariesRuntimeFiles.NativeSubDirectory)' == ''" />

        <RunTimeDependencyCopyLocal
          Include="$(ArtifactsDir)\TargetingPack\**"
          TargetDir="TargetingPack/"/>

        <!-- Wasm App Builder builds as part of tasks, using the corresponding TasksConfiguration -->
        <RunTimeDependencyCopyLocal
          Include="$(ArtifactsBinDir)\WasmAppBuilder\$(TasksConfiguration)\$(NetCoreAppToolCurrent)\**"
          TargetDir="WasmAppBuilder/"/>

        <RunTimeDependencyCopyLocal
          Include="$(ArtifactsBinDir)\MonoTargetsTasks\$(TasksConfiguration)\$(NetCoreAppToolCurrent)\publish\**"
          TargetDir="WasmAppBuilder/"/>

        <RunTimeDependencyCopyLocal
          Include="$(RepoRoot)\src\tests\Common\wasm-test-runner\WasmTestRunner.proj"
          TargetDir="wasm-test-runner/"/>

        <RunTimeDependencyCopyLocal
          Include="$(BrowserProjectRoot)\test-main.js"
          TargetDir="runtime-test/"/>

        <RunTimeDependencyCopyLocal
          Include="$(RepoRoot)\src\tests\Common\wasm-test-runner\index.html"
          TargetDir="runtime-test/"/>

        <RunTimeDependencyCopyLocal
          Include="$(MonoProjectRoot)\wasm\build\*"
          TargetDir="build/"/>
        <RunTimeDependencyCopyLocal
          Include="$(MonoProjectRoot)\browser\build\*"
          TargetDir="build/"/>
    </ItemGroup>

    <ItemGroup>
      <RunTimeDependencyCopyLocal Include="$(CoreDisToolsLibrary)" Condition="$(CopyCoreDisToolsToCoreRoot)" />
    </ItemGroup>

    <ItemGroup Condition="'$(RuntimeFlavor)' == 'mono' and '$(IsDesktopOS)' == 'true' " >
      <!-- Copy the mono version of the coreclr library and SPCL instead of the corceclr one -->
      <RuntimeDependencyCopyLocal Remove="$(CoreCLRArtifactsPath)$(LibPrefix)coreclr$(LibSuffix)" />
      <RuntimeDependencyCopyLocal Remove="$(CoreCLRArtifactsPath)System.Private.CoreLib.dll" />
      <RuntimeDependencyCopyLocal Include="$(MonoArtifactsPath)$(LibPrefix)coreclr$(LibSuffix)" TargetDir="" />

      <RuntimeDependencyCopyLocal Include="$(MonoArtifactsPath)/libmono-component-*" TargetDir=""  />
      <RuntimeDependencyCopyLocal Include="$(MonoArtifactsPath)/*.dll" TargetDir="" />
      <RuntimeDependencyCopyLocal Include="$(MonoArtifactsPath)/libc++.so.1" TargetDir="" Condition="Exists('$(MonoArtifactsPath)/libc++.so.1')" />
      <RuntimeDependencyCopyLocal Include="$(MonoArtifactsPath)/libc++abi.so.1" TargetDir="" Condition="Exists('$(MonoArtifactsPath)/libc++abi.so.1')" />
    </ItemGroup>

    <Copy
      SourceFiles="@(RunTimeDependencyCopyLocal)"
      DestinationFiles="@(RunTimeDependencyCopyLocal -> '$(CORE_ROOT)/%(TargetDir)%(RecursiveDir)%(Filename)%(Extension)')"
      SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
      OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
      Retries="$(CopyRetryCount)"
      RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
      UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)">
      <Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
    </Copy>

  </Target>

  <!-- At this point Common test dependencies don't have any native components -->
  <Target Name="CopyAllNativeProjectReferenceBinaries" />

</Project>
